package com.gl.rent;

import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.core.BaseController;
import com.haixiaoke.saas.repository.core.page.TableDataInfo;
import com.haixiaoke.saas.repository.pojo.Order;
import com.haixiaoke.saas.repository.service.IOrderService;
import com.haixiaoke.saas.repository.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单Controller
 * 
 * @author haixiaoke
 * @date 2023-04-12
 */
@RestController
@RequestMapping("/biz/order")
public class OrderController extends BaseController {
    @Autowired
    private IOrderService orderService;

    /**
     * 查询订单列表
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(Order order) {
        startPage();
        List<Order> list = orderService.selectOrderList(order);
        return getDataTable(list);
    }

    /**
     * 获取订单详细信息
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId) {
        OrderVO orderVO = orderService.selectOrderDetailsByOrderId(orderId);
        if (orderVO == null) {
            return error("获取订单信息失败");
        }
        return success(orderVO);
    }

    /**
     * 新增订单
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:order:add')")
//    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Order order) {
        return toAjax(orderService.insertOrder(order));
    }

    /**
     * 修改订单
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:order:edit')")
//    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Order order) {
        return toAjax(orderService.updateOrder(order));
    }

    /**
     * 删除订单
     */
//    @PreAuthorize("@ss.hasPermi('saas-repository:order:remove')")
//    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds) {
        return toAjax(orderService.deleteOrderByOrderIds(orderIds));
    }
}
